package dissertation.examples.ejb21.message;

import javax.ejb.EJBException;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

public class LogBean implements MessageDrivenBean, MessageListener {
    protected MessageDrivenContext ctx;

    public LogBean() {
    }

    public void onMessage(Message message) {
        if (message instanceof TextMessage){
            TextMessage tm = (TextMessage) message;
            try {
                String text = tm.getText();
                System.out.println("Received new message : " + text);
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }

    public void ejbRemove() throws EJBException {
        System.err.println("ejbRemove()");
    }

    public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException {
        this.ctx = ctx;
    }

    public void ejbCreate() {
        System.err.println("ejbCreate()");
    }
}
